/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ThinkPhpPlugin.Files;

import ThinkPhpPlugin.ThinkphpCreateProject;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.openide.WizardDescriptor;

public final class EntranceVisualPanel1 extends JPanel  implements DocumentListener{
    private EntranceWizardPanel1 panel;

    /** Creates new form EntranceVisualPanel1 */
    public EntranceVisualPanel1(EntranceWizardPanel1 panel) {
        initComponents();
        this.panel = panel;
        entrance_file.getDocument().addDocumentListener(this);
        entrance_fold.getDocument().addDocumentListener(this);
    }

    @Override
    public String getName() {
        return "名称设置";
    }

     @Override
    public void addNotify() {
        super.addNotify();
        entrance_file.requestFocus();
    }

    void read(WizardDescriptor wizardDescriptor) {
        //throw new UnsupportedOperationException("Not yet implemented");
    }

    void store(WizardDescriptor d) {
        /*String action_name=Action_name.getText().trim()+"Action";
        String file_name = p_path+File.separatorChar+"Lib"+File.separatorChar+"Action"+File.separatorChar+action_name+".class.php";
        d.putProperty("file_name", file_name);
        d.putProperty("action_name", action_name);*/
        String entrance_file_str = entrance_file.getText().trim();
        d.putProperty("entrance_file", entrance_file_str);
        String entrance_fold_str=entrance_fold.getText().trim();
        d.putProperty("entrance_fold", entrance_fold_str);
    }

    boolean valid(WizardDescriptor wizardDescriptor) {
        if(entrance_file.getText().length()==0)
        {
            wizardDescriptor.putProperty("WizardPanel_errorMessage",
                    "入口文件不能为空。");
            return false;
        }

        ThinkphpCreateProject tProject=new ThinkphpCreateProject();
        String e_file=tProject.GetProjectDir()+"/"+entrance_file.getText();
        
        if(entrance_fold.getText().length()==0)
        {
            wizardDescriptor.putProperty("WizardPanel_errorMessage",
                    "对应名称不能为空。");
            return false;
        }

        
        wizardDescriptor.putProperty("WizardPanel_errorMessage","");
        return true;
    }

    void validate(WizardDescriptor wizardDescriptor) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        entrance_file = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        entrance_fold = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(EntranceVisualPanel1.class, "EntranceVisualPanel1.jLabel1.text")); // NOI18N

        entrance_file.setText(org.openide.util.NbBundle.getMessage(EntranceVisualPanel1.class, "EntranceVisualPanel1.entrance_file.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(EntranceVisualPanel1.class, "EntranceVisualPanel1.jLabel2.text")); // NOI18N

        entrance_fold.setText(org.openide.util.NbBundle.getMessage(EntranceVisualPanel1.class, "EntranceVisualPanel1.entrance_fold.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(EntranceVisualPanel1.class, "EntranceVisualPanel1.jLabel3.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(entrance_file, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(entrance_fold, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)))
                        .addGap(118, 118, 118))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addContainerGap(46, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(entrance_file, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(entrance_fold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addContainerGap(26, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField entrance_file;
    private javax.swing.JTextField entrance_fold;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables

    // Implementation of DocumentListener --------------------------------------
    public void changedUpdate(DocumentEvent e) {
        updateTexts(e);
    }

    public void insertUpdate(DocumentEvent e) {
        updateTexts(e);
    }

    public void removeUpdate(DocumentEvent e) {
        updateTexts(e);
    }

    /** Handles changes in the Project name and project directory, */
    private void updateTexts(DocumentEvent e) {
        //String action_name=Action_name.getText();
        //String file_name = p_path+File.separatorChar+"Lib"+File.separatorChar+"Action"+File.separatorChar+action_name+"Action.class.php";
        //create_file.setText(file_name);
        panel.fireChangeEvent(); // Notify that the panel changed
    }
}

